package com.delay.queue.model;

import lombok.Data;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @author gxing
 * @desc
 * @date 2021/3/9
 */
@Data
public class MessageTask implements Delayed {
    /**
     * 内容
     */
    private String content;
    /**
     * 发送时间
     */
    private Long extTime;

    public MessageTask(String content, Long extTime) {
        this.content = content;
        this.extTime = extTime;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return extTime - System.currentTimeMillis();
    }

    @Override
    public int compareTo(Delayed o) {
        MessageTask msg = (MessageTask) o;
        return this.extTime - msg.extTime <= 0 ? -1 : 1;
    }
}
